class Cbr < Archive

  protected
    def get_filenames
      raw = unrar("vb")
    end

    def get_file(full_path_in_archive, dest)
      unrar("e", nil, full_path_in_archive, dest)
    end

  private
    def unrar(mode, opts = nil, files = nil, destination = SCRATCH_DIR)
      files = [files].flatten.compact
      opts = [opts].flatten.compact
      opts_str = opts.collect {|o| "-#{o}" }.join(' ')
      cmd = %Q`unrar #{mode} #{opts_str} "#{path}" `
      cmd << files.collect {|f| %Q["#{f}"]}.join(" ") + " " if files.any?
      cmd << "\"#{destination}\"" if mode == "e"
      run(cmd)
    end

end
